package com.bjsxt.reflex;

import java.lang.reflect.Field;

public class GetField {
    public static void main(String[] args) throws NoSuchFieldException {
        Class clazz= Users.class;
        Field[] fields = clazz.getFields();
        for (Field f:fields){
            System.out.println(f);
            System.out.println(f.getName());
        }
        System.out.println("---------------------------");
        Field[] fields2 = clazz.getDeclaredFields();
        for (Field f:fields2){
            System.out.println(f);
            System.out.println(f.getName());
        }
        System.out.println("---------------------------");
        Field field = clazz.getField("age");//只能取public
        System.out.println(field.getName());
        System.out.println("---------------------------");
        Field field2 = clazz.getDeclaredField("username");
        System.out.println(field2);
    }
}
